#ifndef _SRV_LOG_H_INCLUDED_
#define _SRV_LOG_H_INCLUDED_

#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SRV_LOG_STDERR          0
#define SRV_LOG_EMERG           1
#define SRV_LOG_ALERT           2
#define SRV_LOG_CRIT            3
#define SRV_LOG_ERR             4
#define SRV_LOG_WARN            5
#define SRV_LOG_NOTICE          6
#define SRV_LOG_INFO            7
#define SRV_LOG_DEBUG           8

#define SRV_MAX_ERROR_STR       2048

typedef struct srv_log_s        srv_log_t;

struct srv_log_s {
    int                         log_level;
    char                       *name;
    int                         fd;
    struct tm                   last_write;
};

int srv_log_stol(char *s);

srv_log_t *srv_log_create(char *name, int log_level);

void srv_log_destroy(srv_log_t *log);

#define srv_log_error(level, log, ...) \
    if ((log)->log_level >= level) srv_log_error_core(level, log, __VA_ARGS__)

void srv_log_error_core(unsigned level, srv_log_t *log, int err, const char *fmt, ...);


void srv_log_test();

#ifdef __cplusplus
}
#endif

#endif /* _SRV_LOG_H_INCLUDED_ */
